<template>
  <div class="login">
    <div class="login-form">
      <p>用户登录</p>
      <div class="login-form-inputbox">
        <el-input
          placeholder="用户名"
          prefix-icon="el-icon-user-solid"
          v-model="user.telephone"
        >
        </el-input>
        <el-input
          placeholder="密码"
          prefix-icon="el-icon-lock"
          v-model="user.password"
          type="password"
        >
        </el-input>
      </div>
      <div class="login-form-operatebox">
        <!-- <a href="#" class="operatebox-forget">忘记密码?</a> -->
        <div style="text-align: center; width: 260px">
          <el-button type="primary" round @click="loging1">登录</el-button>
        </div>
        <div style="text-align: center; width: 260px">
          <el-button type="primary" round @click="loging2">管理员登录</el-button>
        </div>
        <a @click="register" class="operatebox-register">注册</a>
      </div>
    </div>
  </div>
</template>

<script>
import api from "../network/home";

export default {
  name: "Login",
  data() {
    return {
      user: {
        telephone: "",
        password: "",
      },
    };
  },
  methods: {
    loging1() {
      const params = {
        telephone: this.user.telephone,
        password: this.user.password,
      }
      api.userLogin(params).then(res=>{
        console.log(res);
        if(res.data.code=="200") {
          this.$router.push('./userHome')
          localStorage.setItem('gymToken', res.data.data)
        } else {
          this.$message.error(res.data.data);
        }
      })
    },
    loging2() {
      const params = {
        telephone: this.user.telephone,
        password: this.user.password,
      }
      api.loginAdmin(params).then(res=>{
        console.log(res);
        if(res.data.code=="200") {
          this.$router.push('./home')
          localStorage.setItem('gymToken', res.data.data)
        } else {
          this.$message.error(res.data.data);
        }
      })
    },
    register(){
      this.$router.push('./register')
    }
  },
};
</script>

<style lang="scss" scoped>
.login {
  background-image: url("../assets/bgc.jpeg");
  background-size: 100% 100%;
  background-repeat: no-repeat;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}
.login-form {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background-color: #eee;
  width: 260px;
  height: 400px;
  padding: 0 43px;
  p {
    text-align: center;
    padding: 20px;
    // box-shadow: 0px 15px 1px -15px #000;
    border-bottom: 1px solid rgba(145, 141, 141, 0.144);
  }
}
.login-form-inputbox {
  height: 100px;
  font-size: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 37px 5px;
  justify-content: space-between;
}
.login-form-operatebox {
  height: 150px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  text-align: center;
}
.operatebox-forget {
  color: rgb(119, 115, 115);
  text-decoration: none;
}
.operatebox-register {
  cursor: pointer;
  color: rgb(11, 162, 207);
}
::v-deep .el-input__inner {
  border-radius: 50px;
  padding-left: 50px;
  height: 45px;
}
::v-deep .el-input__icon {
  font-size: 20px;
  padding: 0 10px;
}
.el-button {
  width: 100%;
}
</style>
